# -*- coding: utf-8 -*-
from xTkinter import *
import tkMessageBox as MsgBox

#from BaseDonnees import *

class VueClient(Frame):
    def __init__(self,master,parent,**cnf):
        KeysList=cnf.keys()
        self.parent = parent
        self.master=master
        self.width=400
        self.height=200
        if ('width' in KeysList):
            self.width=cnf['width']
        if ('width' in KeysList):
            self.height=cnf['height']
        Frame.__init__(self,master,cnf)
        self.ListeEntry = []  
        self.master.update()
        self.x=self.master.winfo_width()/2-(self.width/2)
        self.y=self.master.winfo_height()/2-(self.height/2)       
        self.place(x=self.x,y=self.y)
        self.configure(width=536,height=300)
        self.prec=xButton(self,text='Precedent',height=1,width=10)
        self.prec.place(x=49,y=2)
        self.Suiv=xButton(self,text='Suivant',height=1,width=10)
        self.Suiv.place(x=140,y=2)
        self.rech=xButton(self,text='Recherche',height=1,width=10, command =self.enregistrement)
        self.rech.place(x=237,y=2)
        self.ajout=xButton(self,text='Ajouter',height=1,width=10)
        self.ajout.place(x=332,y=2)
        self.supp=xButton(self,text='Supprimer',height=1,width=10)
        self.supp.place(x=428,y=2)
        self.no=xLabel(self,text='Code',height=1,width=10)
        self.no.place(x=18,y=49)
        self.nom=xLabel(self,text='Nom',height=1,width=10)
        self.nom.place(x=18,y=93)
        self.pren=xLabel(self,text='Prenom',height=1,width=10)
        self.pren.place(x=18,y=116)
        self.phone=xLabel(self,text='Telephone',height=1,width=10)
        self.phone.place(x=18,y=140)
        self.adr=xLabel(self,text='Adresse',height=1,width=10)
        self.adr.place(x=18,y=164)
        self.city=xLabel(self,text='Ville',height=1,width=10)
        self.city.place(x=18,y=187)
        self.state=xLabel(self,text='Pays',height=1,width=10)
        self.state.place(x=18,y=210)
        self.country=xLabel(self,text='Province',height=1,width=10)
        self.country.place(x=18,y=233)
        self.CP=xLabel(self,text='Code Postal',height=1,width=12)
        self.CP.place(x=18,y=255)
        self.saisino=xEntry(self,width=12)
        self.saisino.place(x=119,y=49)
        self.saisinom=xEntry(self,width=25)
        self.saisinom.place(x=119,y=94)
        self.saisipren=xEntry(self,width=25)
        self.saisipren.place(x=119,y=118)
        self.saisitel=xEntry(self,width=25)
        self.saisitel.place(x=119,y=141)
        self.saisiadr=xEntry(self,width=25)
        self.saisiadr.place(x=119,y=165)
        self.saisicity=xEntry(self,width=25)
        self.saisicity.place(x=119,y=189)
        self.saisistate=xEntry(self,width=25)
        self.saisistate.place(x=119,y=212)
        self.saisiprov=xEntry(self,width=25)
        self.saisiprov.place(x=119,y=235)
        self.saisicp=xEntry(self,width=25)
        self.saisicp.place(x=119,y=257)
        self.repsal=xLabel(self,text='Representant Commercial',height=1,width=25)
        self.repsal.place(x=356,y=67)
        self.repsal=xEntry(self,width=25)
        self.repsal.place(x=356,y=92)
        self.limiteCredit=xLabel(self,text='Limite de Credit',height=1,width=25)
        self.limiteCredit.place(x=359,y=124)
        self.limCrdt=xEntry(self,width=25)
        self.limCrdt.place(x=359,y=151)
        self.Reg=xLabel(self,text='Region',height=1,width=12)
        self.Reg.place(x=361,y=188)
        self.Region=xEntry(self,width=25)
        self.Region.place(x=360,y=214)
        self.place(x=0,y=0)
        self.Indice=0
        self.ListeEntry.append(self.saisino)
        self.ListeEntry.append(self.saisinom)
        self.ListeEntry.append(self.saisipren)
        self.ListeEntry.append(self.saisitel)
        self.ListeEntry.append(self.saisiadr)
        self.ListeEntry.append(self.saisiadr)
        self.ListeEntry.append(self.saisicity)
        self.ListeEntry.append(self.saisistate)
        self.ListeEntry.append(self.saisiprov)
        self.ListeEntry.append(self.saisicp)
        self.ListeEntry.append(self.repsal)
        self.ListeEntry.append(self.limCrdt)
        self.ListeEntry.append(self.Region)
        self.BindEntry()
            
    def BindEntry(self):
        for index in range(len(self.ListeEntry) - 1):
            print "test"
            self.ListeEntry[index].bind("<Return>", lambda index: self.ChangerFocus)
    
    def ChangerFocus(e, index):
        print "changerfocus"
       # print index
        #self.ListeEntry[index + 1].icursor
        
    def enregistrement(self):
        self.NomsChamps=['id', 'Name', 'phone','address','city', 'state', 'country', 'zip code', 'credit rating']
        self.TableSelectionnee=[s_customer]
        Message = self.parent.BaseDonnees.ObtenirEnregistrement(NomsChamps, TableSelectionnee )
        if Message[0] == 1:
           self.ListeEnregistrement = Message[1]
        else:
           msgBox.showerror('PERP 2009 | �dition des tables', 'Une erreur est survenue!\n'+Message[1])
            
if __name__ == '__main__':
    root=Tk()
    root.geometry('550x300')
    monInstance=VueClient(root,None)
    root.mainloop()
    pass

